package com.project;

import com.project.service.IManService;
import com.project.service.impl.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    public static void main(String[] args) {
        //加载spring的配置文件，得到spring上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//        //从容器中得到spring组件，按类型方式匹配，如果按接口匹配,该接口只能有一个实现类
////        IManService service = context.getBean(IManService.class);
//        //从容器中得到spring组件，按id名称匹配
//        IManService service = (IManService)context.getBean("CN");
//        IManService s1 = (IManService)context.getBean("CN");
//        System.out.println(service == s1);
//        service.run();
//        //关闭容器
//        ((ClassPathXmlApplicationContext) context).close();

//        IManService service = (IManService) context.getBean("CN");
//        service.run();

        Student student = (Student) context.getBean("student");
        System.out.println(student);
    }
}
